package com.situ.company.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.situ.company.dao.IRoleDao;
import com.situ.company.entity.Role;
import com.situ.company.util.JDBCUtil;

public class RoleDaoImpl implements IRoleDao {

	@Override
	public List<Role> selectAll() {
		Connection connection = null;
		PreparedStatement statement = null;
		ResultSet resultSet = null;
		List<Role> list = new ArrayList<Role>();
		try {
			connection = JDBCUtil.getConnection();
			String sql = "select id,name from role";
			statement = connection.prepareStatement(sql);
			System.out.println(statement);
			resultSet = statement.executeQuery();
			while (resultSet.next()) {
				int id = resultSet.getInt("id");
				String name = resultSet.getString("name");
				Role role = new Role(id, name);
				list.add(role);
			}
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return list;
	}

}
